import axios from 'axios'
import store from '@/store'

//创建axios实例
const service = axios.create({
  baseURL: process.env.BASE_API, // api的base_url
})

service.interceptors.request.use(
  config => {
    //如果token为空，则在headers中添加token，否则直接返回
    //alert(222);
    if (store.state.token) {
      //alert(333);
      config.headers['token'] = window.sessionStorage.getItem("token")
    }
    return config
  },
  error => {
    // do something with request error
    console.log(error) // for debug
    return Promise.reject(error)
  }
)
export default service
